#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void)
{
	fd_set rfd, c_rfd;
	int rv, /* ki, */ fd, i;
	char cline[100], ch;
	unsigned long li1, li2;
	struct timeval time_out;

	FD_ZERO(&rfd);
	FD_SET(0, &rfd);

	time_out.tv_usec = 10;
	time_out.tv_sec = 1;
	i = 0;

	do
	{
		c_rfd = rfd;
		rv = select(1, &c_rfd, 0, 0, &time_out);

		if (FD_ISSET(0, &c_rfd))
		{
			read(0, &ch, 1);
			if (ch == 'x') break;
			cline[i] = ch;
			if (ch < 0x20)
			{
				cline[i] = 0;
				printf("\nGOT STRING => %s\n", cline);
				for (li1 = 0; li1 < 855; li1++)
					for (li2 = 0; li2 < 65500; li2++);
				i = 0;
			}
			else i++;
		}
		write(1, "-", 1);
		for (li1 = 0; li1 < 855; li1++)
			for(li2 = 0; li2 < 65500; li2++);
	}
	while (1);
	close(fd);
	return 0;
}

